package com.njtoyo.taxi.admin.rest.controller.business.geo;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.njtoyo.taxi.admin.mapper.master.entity.VehicleModel;
import com.njtoyo.taxi.admin.service.business.geo.VehicleModelService;
import com.taxi.entity.common.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("business/geo/vehicle_model")
public class VehicleModelController {
    @Autowired
    private VehicleModelService vehicleModelService;

    @RequestMapping("/page")
    public RestResult page(@RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                           @RequestParam(value = "size", required = false, defaultValue = "15") Integer size) {
        return vehicleModelService.page(current, size);
    }

    @GetMapping("/listAll")
    public RestResult listAll() {
        return vehicleModelService.listAll();
    }

    @PostMapping("/add")
    public RestResult add(@RequestBody VehicleModel vehicleModel) {
        if (StrUtil.isBlank(vehicleModel.getName())) {
            return RestResult.failed("请输入车辆型号名称");
        }
        if (StrUtil.isBlank(vehicleModel.getCode())) {
            return RestResult.failed("请输入车辆型编码");
        }
        return vehicleModelService.add(vehicleModel);
    }
    @PostMapping("/update")
    public RestResult update(@RequestBody VehicleModel vehicleModel) {
        if (ObjectUtil.isNull(vehicleModel.getId())) {
            return RestResult.failed("缺少必要参数:ID");
        }
        if (StrUtil.isBlank(vehicleModel.getName())) {
            return RestResult.failed("请输入车辆型号名称");
        }
        if (StrUtil.isBlank(vehicleModel.getCode())) {
            return RestResult.failed("请输入车辆型编码");
        }
        return vehicleModelService.update(vehicleModel);
    }

}
